<?php

/**
 *  Ini adalah project open source yang dikembangkan oleh Impossible Team
 *
 *  Copyright (c) 2011 ekoindri. <ekoindri@ekoindri.com>
 *
 *  Versi: 1.2
 *  Developed by: Impossible Team
 *  Leader: Eko Indriyawan
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *  USA
 *
 */

require_once("rpcl/rpcl.inc.php");
  //Includes
use_unit("webservices.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

function GURU_SIMPAN($connection_string, $guru, $status){

  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());

  if($status == 'NEW') {

    $query = "
            INSERT INTO TABEL_GURU
            (
            GURU_KODE,
            GURU_NAMA_AWAL,
            GURU_NAMA_TENGAH,
            GURU_NAMA_AKHIR,
            GURU_STATUS,
            GURU_KELAS,
            GURU_UMUR,
            GURU_ALAMAT,
            GURU_KOTA,
            GURU_PROPINSI,
            GURU_KETERANGAN
            )
            VALUES
            (
            '" . $guru[GURU_KODE] . "',
            '" . $guru[GURU_NAMA_AWAL] . "',
            '" . $guru[GURU_NAMA_TENGAH] . "',
            '" . $guru[GURU_NAMA_AKHIR] . "',
            '" . $guru[GURU_STATUS] . "',
            '" . $guru[GURU_KELAS] . "',
            '" . $guru[GURU_UMUR] . "',
            '" . $guru[GURU_ALAMAT] . "',
            '" . $guru[GURU_KOTA] . "',
            '" . $guru[GURU_PROPINSI] . "',
            '" . $guru[GURU_KETERANGAN] . "'
            )";
    } else {
    $query = "
            UPDATE    TABEL_GURU
            SET       GURU_KODE          = '" . $guru[GURU_KODE] . "',
                      GURU_NAMA_AWAL     = '" . $guru[GURU_NAMA_AWAL] . "',
                      GURU_NAMA_TENGAH   = '" . $guru[GURU_NAMA_TENGAH] . "',
                      GURU_NAMA_AKHIR    = '" . $guru[GURU_NAMA_AKHIR] . "',
                      GURU_STATUS       = '" . $guru[GURU_STATUS] . "',
                      GURU_KELAS         = '" . $guru[GURU_KELAS] . "',
                      GURU_UMUR          = '" . $guru[GURU_UMUR] . "',
                      GURU_ALAMAT        = '" . $guru[GURU_ALAMAT] . "',
                      GURU_KOTA          = '" . $guru[GURU_KOTA] . "',
                      GURU_PROPINSI      = '" . $guru[GURU_PROPINSI] . "',
                      GURU_KETERANGAN    = '" . $guru[GURU_KETERANGAN] . "'
            WHERE     ID                  = '" . $guru[ID] . "'
            ";
    }

  $result = mysql_query($query) or die(mysql_error());

  }

function GURU_SIMPAN_DATASET($connection_string, $daftarguru){

  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());

  for($x = 0; $x < 100; $x++){
    $guru = $daftarguru[$x];
    if($guru[GURU_KODE] != '') {

      $query = "
            INSERT INTO TABEL_GURU
            (
            GURU_KODE,
            GURU_NAMA_AWAL,
            GURU_NAMA_TENGAH,
            GURU_NAMA_AKHIR,
            GURU_STATUS,
            GURU_KELAS,
            GURU_UMUR,
            GURU_ALAMAT,
            GURU_KOTA,
            GURU_PROPINSI,
            GURU_KETERANGAN
            )
            VALUES
            (
            '" . $guru[GURU_KODE] . "',
            '" . $guru[GURU_NAMA_AWAL] . "',
            '" . $guru[GURU_NAMA_TENGAH] . "',
            '" . $guru[GURU_NAMA_AKHIR] . "',
            '" . $guru[GURU_STATUS] . "',
            '" . $guru[GURU_KELAS] . "',
            '" . $guru[GURU_UMUR] . "',
            '" . $guru[GURU_ALAMAT] . "',
            '" . $guru[GURU_KOTA] . "',
            '" . $guru[GURU_PROPINSI] . "',
            '" . $guru[GURU_KETERANGAN] . "'
            )
            ";
      $result = mysql_query($query) or die(mysql_error());

      }
    }
  }

function GURU_DATA(
$connection_string,
$row,
$key_word,

$sort_type){
  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());

  $sql = "
  SELECT    *
  FROM      TABEL_GURU
  WHERE     GURU_NAMA_AWAL LIKE '" . $key_word . "'
  OR        GURU_NAMA_TENGAH LIKE '" . $key_word . "'
  OR        GURU_NAMA_AKHIR LIKE '" . $key_word . "'
  OR        GURU_ALAMAT LIKE '" . $key_word . "'
  OR        GURU_KOTA LIKE '" . $key_word . "'
  OR        GURU_PROPINSI LIKE '" . $key_word . "'
  ORDER BY  GURU_KODE " . $sort_type . "
  LIMIT 0, " . $row;
  $result = mysql_query($sql);

  $numrows = mysql_num_rows($result);
  $gurulist = array();
  for($x = 0; $x < $numrows; $x++){
    $gurulist[] = mysql_fetch_array($result);
    }

  mysql_close();
  return $gurulist;
  }

function GURU_DATA_SEMUA(
$connection_string,
$sort_type){
  $cek = mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  if($cek) {
    $cek2 = mysql_select_db($connection_string[server_database]) or die(mysql_error());
    if($cek) {

      $sql = "
      SELECT    *
      FROM      TABEL_GURU
      ORDER BY  ID " . $sort_type;
      $result = mysql_query($sql);

      $numrows = mysql_num_rows($result);
      $gurulist = array();
      for($x = 0; $x < $numrows; $x++){
        $gurulist[] = mysql_fetch_array($result);
        }

      mysql_close();
      return $gurulist;
      }
    }
  }

function GURU_HAPUS(
$connection_string,

$id){
  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());

  $sql = "
  DELETE FROM TABEL_GURU
  WHERE     ID = " . $id;

  $result = mysql_query($sql);

  mysql_close();
  return ('Sukses');
  }

  //Class definition
class DM_GURU extends DataModule{
  public $SIS_GURU = null;
  function SIS_GURUAddComplexTypes($sender, $params){

    $this->SIS_GURU->addComplexType(
    "TInfoServer",
    "complexType",
    "struct",
    "all",
    "",
    array(
          "server_host"=>array("name"=>"Nama", "type"=>"xsd:string"),
          "server_database"=>array("name"=>"Umur", "type"=>"xsd:string"),
          "server_username"=>array("name"=>"Kelas", "type"=>"xsd:string"),
          "server_password"=>array("name"=>"Kota", "type"=>"xsd:string")
          )
    );

    $this->SIS_GURU->addComplexType(
    "TInfoGuru",
    "complexType",
    "struct",
    "all",
    "",
    array(
          "ID"=>array("name"=>"ID", "type"=>"xsd:integer"),
          "GURU_KODE"=>array("name"=>"GURU_KODE", "type"=>"xsd:string"),
          "GURU_NAMA_AWAL"=>array("name"=>"GURU_NAMA_AWAL", "type"=>"xsd:string"),
          "GURU_NAMA_TENGAH"=>array("name"=>"GURU_NAMA_TENGAH", "type"=>"xsd:string"),
          "GURU_NAMA_AKHIR"=>array("name"=>"GURU_NAMA_AKHIR", "type"=>"xsd:string"),
          "GURU_STATUS"=>array("name"=>"GURU_STATUS", "type"=>"xsd:string"),
          "GURU_KELAS"=>array("name"=>"GURU_KELAS", "type"=>"xsd:integer"),
          "GURU_UMUR"=>array("name"=>"GURU_UMUR", "type"=>"xsd:integer"),
          "GURU_ALAMAT"=>array("name"=>"GURU_ALAMAT", "type"=>"xsd:string"),
          "GURU_KOTA"=>array("name"=>"GURU_KOTA", "type"=>"xsd:string"),
          "GURU_PROPINSI"=>array("name"=>"GURU_PROPINSI", "type"=>"xsd:string"),
          "GURU_KETERANGAN"=>array("name"=>"GURU_KETERANGAN", "type"=>"xsd:string")
          )
    );

    $this->SIS_GURU->addComplexType(
    'TInfoDaftarGuru',
    'complexType',
    'array', '',
    'SOAP-ENC:Array', array(),
    array
      (
      array
        (
        'ref'=>'SOAP-ENC:arrayType',
        'wsdl:arrayType'=>'tns:TInfoGuru[]'
        )
      ),
    'tns:TInfoGuru'
    );

    }

  function SIS_GURURegisterServices($sender, $params){

    $this->SIS_GURU->register
    (
    "GURU_SIMPAN",
    array(
          'connection_string'=>'tns:TInfoServer',
          'GURU'=>'tns:TInfoGuru',
          'status'=>'xsd:string'),
    array('return'=>'xsd:string'),
    'http://localhost/'
    );

    $this->SIS_GURU->register
    (
    "GURU_SIMPAN_DATASET",
    array(
          'connection_string'=>'tns:TInfoServer',
          'daftarguru'=>'tns:TInfoDaftarGuru'),
    array('return'=>'xsd:string'),
    'http://localhost/'
    );

    $this->SIS_GURU->register(
    "GURU_DATA",
    array(
          'connection_string'=>'tns:TInfoServer',
          'row'=>'xsd:integer',
          'key_word'=>'xsd:string',
          'sort_type'=>'xsd:string'),
    array('return'=>'tns:TInfoDaftarGuru')
    );

    $this->SIS_GURU->register(
    "GURU_DATA_SEMUA",
    array(
          'connection_string'=>'tns:TInfoServer',
          'sort_type'=>'xsd:string'),
    array('return'=>'tns:TInfoDaftarGuru')
    );

    $this->SIS_GURU->register
    (
    "GURU_HAPUS",
    array(
          'connection_string'=>'tns:TInfoServer',
          'id'=>'xsd:integer'),
    array('return'=>'xsd:string'),
    'http://localhost/'
    );

    }
  }

global $application;

global $DM_GURU;

  //Creates the form
$DM_GURU = new DM_GURU($application);

  //Read from resource file
$DM_GURU->loadResource(__FILE__);

?>